package org.youyee.game.utils.bitmapCacheUtils
{
	import flash.display.MovieClip;
	import flash.geom.Matrix;

	/**
	 * 缓存MovieClip数据 
	 * @author youyeelu
	 * 
	 */	
	public class BitmapCacheClipData
	{
		/**
		 * 位置矩阵 
		 */		
		public var matrix:Matrix;
		
		/**
		 * 帧队列 
		 */		
		public var frames:Array = [];
		
		/**
		 * 跳帧参数 
		 */		
		public var numJumpFrames:int = 1;
		
		/**
		 * 进行缓存 
		 * @param movieClip 需要被执行缓存的MovieClip
		 * @param numJumpFrame 跳帧选项
		 * @return 缓存好的数据
		 * 
		 */		
		public static function buildBitmapCacheData(movieClip:MovieClip, numJumpFrames:int=1):BitmapCacheClipData
		{
			if (!movieClip)
			{
				return null;
			}
			
			var frames:Array = [];
			var len:int = movieClip.totalFrames;
			var frame:BitmapCacheFrame;
			
			for (var i:int=1; i<=len; i+=numJumpFrames)
			{
				movieClip.gotoAndPlay(i);
				frame = BitmapCacheFrame.buildCacheFrame(movieClip);
				frames.push(frame);
			}
			
			var data:BitmapCacheClipData = new BitmapCacheClipData();
			
			data.frames = frames;
			data.matrix = movieClip.transform.matrix;
			data.numJumpFrames = numJumpFrames;
			
			return data;
		}
		
		/**
		 * 销毁 
		 * 
		 */		
		public function dispose():void
		{
			this.frames = null;
		}
	}
}